Skip to content

fix(remote): drop a remote artifact whose name cannot be a file name - #4718

Merged
thymikee merged 6 commits into
callstack:mainfrom
zerone0x:fix/remote-artifact-nul-name
Nov 23, 2026
Merged

thymikee merged 6 commits into
callstack:mainfrom
zerone0x:fix/remote-artifact-nul-name

Conversation

@zerone0x

@zerone0x zerone0x commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Drop raw NUL names for ordinary capture fallbacks and unnamed record stops before download. Preserve caller-authorized destinations and the action result. Ordinary capture fallbacks keep valid POSIX colon names and reject drive-qualified basenames under Windows path rules. Dropped artifacts report artifact_name_invalid and a warning.

Fixes #4661. Host-kit name policy and typed public disclosure remain follow-ups.

Before / after

The same loopback tests exercise raw fallback names, all three recording fields, and POSIX response and generated names.

Previous PR head dea29a6a1acfc0ddd9643bcf83fa63e5acffacf4
6 failed, 28 passed

Current head 192b54f64dbc6ad92b89abe156f232a8a33e43ac
34 passed. NUL cases retained the action result with zero requests and writes.
Both POSIX cases wrote in cwd. Both Windows path-rule cases dropped before download.

Earlier explicit-null snapshot probe.

Base 721adbc6985f4af72edd148a27a4de3eee7bfbf1
$ node --disable-warning=ExperimentalWarning --experimental-strip-types snapshot-artifact-probe.mjs
{"ok":true,"nodes":3,"artifactGets":1,"filesWritten":1,"drops":[]}

Head dea29a6a1acfc0ddd9643bcf83fa63e5acffacf4
$ node --disable-warning=ExperimentalWarning --experimental-strip-types snapshot-artifact-probe.mjs
{"ok":true,"nodes":3,"artifactGets":0,"filesWritten":0,"drops":[{"field":"path","reason":"artifact_name_invalid"}]}

Validation

  • 192b54f64dbc6ad92b89abe156f232a8a33e43ac passed all 343 focused remote and offline wire tests. Released-wire compatibility passed against v0.21.42 at protocol 3.
  • Format, lint, typecheck, layering, Fallow, and build passed in the affected run. All 410 related tests passed on rerun with local ZIP tools. CI covers the remaining unit and smoke lanes.
  • Live Chromium through the built CLI and HTTP daemon proxy at dea29a6a1acfc0ddd9643bcf83fa63e5acffacf4. Verified the PNG signature and both playable WebMs. Native iOS and Android targets were unavailable. Measured run.
Client cwd: /home/admin/scratch/agent-device-4718-live.EbqWO2/client-output-XnQkQr
screenshot shot.png             -> cwd/shot.png (7,119 bytes)
record start/stop named.webm    -> cwd/named.webm (9,262 bytes)
record start/stop               -> cwd/recording-1795357113663.webm (9,240 bytes)
Saved remote recording file to /home/admin/scratch/agent-device-4718-live.EbqWO2/client-output-XnQkQr/recording-1795357113663.webm in the current directory because this request named no destination.
The named video had no cwd warning. Its telemetry sidecar did.

Isolated loopback tests detected all 11 mutations.

Mutated behavior Detected Failing loopback cases
Record fallback NUL guard 3/3 Recording destination and NUL names
Ordinary name guard 3/3 Ordinary capture names and NUL directory part
Windows drive guard 3/3 POSIX names and Windows drive basenames
Ordinary fallback return 2/2 Successful ordinary capture

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

@zerone0x
zerone0x force-pushed the fix/remote-artifact-nul-name branch from e99e7fe to 16c7e5e Compare November 18, 2026 20:13
@thymikee

Copy link
Copy Markdown
Member

At 16c7e5e, the change still has two delivery defects and needs live verification.

The destination check rejects NUL but accepts a peer-selected fallback name longer than the filesystem component limit. Opening it fails with ENAMETOOLONG and loses the answered action. Please apply a host-kit name admission rule to every peer-selected entry before filesystem work, disclose invalid names, and cover overlong names and the platform cases in its table.

The dropped reason exists only on an untyped remote response; screenshot normalization discards it. Node and default screenshot JSON consumers cannot reliably identify the dropped artifact by its typed reason, and the daemon path can still appear as successful output. Please own the disclosure in the shared response contract and carry it through client normalizers and machine output, preserving the warning and identifying unavailable paths.

The remote capture delivery change has no live verification at this head. Please run a remote device capture through the daemon client and a public output surface, including a malformed artifact response, and show successful action data, the typed dropped reason and warning, and no dropped file.

Not blocking: the regression could use a remote request with a malformed response through the daemon client and a public surface, asserting the kept action, typed disclosure and no artifact write; you can take or leave this suggestion.

Could a single host-kit peer-entry admission rule and shared typed delivery disclosure be used at materialization? The host-kit owner would first need to agree on the name policy and platform case table, since issue #4669 defers the broader write policy.

Coverage failed; please check its log for the failing assertion or threshold and compare it with main. The PR body describes validation at e99e7fe, not at this head. No conflicts are known. Before merge, please repair name admission and disclosure, provide live evidence at this head, and diagnose Coverage.

@thymikee

Copy link
Copy Markdown
Member

This branch now conflicts with main. Please rebase or merge main and push; the earlier review points on 16c7e5e still stand and will be re-checked on the new head.

@zerone0x
zerone0x force-pushed the fix/remote-artifact-nul-name branch from 16c7e5e to 4b76187 Compare November 21, 2026 14:13
@zerone0x

Copy link
Copy Markdown
Contributor Author

Rebased onto 721adbc698 and pushed 4b761875ecde1b9fbeb5907eebe2896935bd58b2. The conflict is resolved, and the rebase preserves main's record-stop destination and generated-name fallback rules.

Coverage failed on wire declaration drift, stale compatibility acknowledgments, and the missing DroppedArtifact manifest entry. The offline wire checks passed 6/6 on clean main. I updated the manifest and ledger on this branch. The focused artifact and wire tests passed 30/30, and the released-wire check passed against v0.21.41 with the protocol version unchanged. Full Coverage awaits CI.

The earlier review remains open. Overlong names and platform-specific cases need the host-kit owner's agreement on name admission. Shared typed disclosure, warning and unavailable-path handling through Node and default screenshot JSON, and live remote device capture evidence also remain open at this head.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

The earlier conflict at 16c7e5e is resolved, and coverage, which failed there, is green at 4b76187. Three code issues and one missing validation remain.

The extracted downloadOneArtifact now carries every non-script remote capture artifact, including record stop with its staged file and recording.add. No live run exists at 4b76187, and the PR body says device verification is still open. Before merge, run a live remote session through the daemon client at this commit. Run a screenshot or snapshot capture, and a record start/stop with and without an output path. The output must show the client-side file written at the reported path, plus the recording warning for the cwd fallback. The malformed-name case can stay covered by the loopback test, because a real daemon cannot emit it.

A second independent pass found a likely defect at daemon-artifacts.ts:745. A successful remote snapshot can list an artifact with fileName: null and no registered destination. The HTTP response parser passes the null through, the resolver turns it into an empty string and generates path-<timestamp>, and the client downloads it with no artifact_name_invalid entry. Should only an omitted fileName default to the empty-name fallback, with an explicit null rejected by the same type check as other non-string names? The record-stop branch can stay as it is.

A second independent pass found a likely defect at daemon-artifacts.ts:752. With a Windows client, a working directory on D:, and no authorized destination, a fallback name such as subdir/C:shot.png leaves a drive-relative component after basename. The resolver then picks a path on C:, outside the working directory. The base has the same path calculation, but this breaks the destination invariant this PR states. A Windows drive-qualified basename should take the existing artifact_name_invalid branch before the ordinary capture fallback resolves. The same check should apply to the basename used to build an empty-name fallback.

Not blocking: downloadOneArtifact retypes recording inline as { add(...) } | undefined, and the delivery shape is declared twice, once at line 540 and once in the parameter type, so typing the parameter from recordingDelivery or keeping the loop body inline would remove the duplicate, and you can take or leave this.

The two failing checks are both 'Body rules'. That gate grades only the PR title and body, so the code diff does not touch it. The likely cause is the Before / after section, which shows no base and head calls with differing output. Please edit the body to fix it.

Not verified here: the focused tests and the released-wire check were not rerun, and the Body rules failure excerpt was not inspected. The earlier points on overlong names and typed disclosure through client normalizers fall outside this round's invariant and fit follow-up issues.

The live remote capture evidence and a PR body that passes the Body rules gate are needed before merge.

@zerone0x

Copy link
Copy Markdown
Contributor Author

Pushed dea29a6a1acfc0ddd9643bcf83fa63e5acffacf4.

  • Omitted fileName still uses the generated fallback. Explicit null now reaches the existing artifact_name_invalid result, like the other non-string names.
  • A drive-qualified basename now reaches the same result before the client resolves an ordinary capture destination. This also covers the basename used to generate an empty-name fallback. Record stop follows its existing destination rules.
  • The body includes measured base and head output from the same loopback snapshot and passed pnpm gate pr-body locally. The focused suite passed 79 tests, all 404 related tests passed, and released-wire compatibility passed against v0.21.41. The local aggregate runner reported a process cleanup failure after the related suite. Body rules passed on GitHub.
  • A live Chromium session through the built CLI and HTTP proxy wrote the screenshot and both WebMs at their reported client paths. The unnamed recording included the cwd warning for the video. The named video used its requested path, and its telemetry sidecar retained the cwd warning. No native iOS or Android target was available.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

The findings from the earlier review are addressed, but three gaps remain at dea29a6, so this needs changes before merge.

A second independent pass found that a successful remote snapshot with no registered destination can return a fileName with a NUL in the directory part, such as <NUL>/shot.png (daemon-artifacts.ts:747). basename discards that part, the chosen path no longer contains NUL, and the client writes cwd/shot.png without artifact_name_invalid. Issue #4661 requires a NUL-containing name to be dropped. Please reject a NUL in the raw ordinary fallback name before taking its basename, and reuse the existing undefined destination result so the drop is disclosed before any download.

A second independent pass found that an unnamed remote record stop can return an outPath, chunkPath or telemetryPath artifact whose fileName contains a NUL (daemon-artifacts.ts:739). localFileName rejects the string, but the UUID fallback then downloads it and reports recording_destination_not_requested. Issue #4661 requires no write and artifact_name_invalid for an explicit NUL name. Please reject an explicit NUL string before the record-stop name fallback, and keep the current destination precedence and the other generated-name cases.

A second independent pass found that the drive-prefix check drops valid POSIX names (daemon-artifacts.ts:752). On a POSIX client, a successful capture with no registered destination and fileName C:shot.png wrote cwd/C:shot.png before this change. It is now dropped. An empty name whose generated basename starts with the same prefix changes the same way. Please apply the drive-prefix check only under Windows path semantics, after the response or generated basename is chosen and before it is resolved.

Not blocking, and these can be taken or left: the explicit-null row in daemon-artifacts-capture.test.ts (line 181) casts null as unknown as string, so typing the field as string | null and casting once at the call site would be cleaner, and if the host-kit name policy follow-up named in the PR body lands, the drive-prefix check can fold into that single policy.

Not verified here: the focused tests, the wire-compat check and the loopback probe were not rerun, and the win32 behavior of the drive check comes from Node path.basename semantics, not an observed Windows run. A head SHA on the live-run bullet in the PR body would remove any doubt about which code it exercised.

Only Body rules is not passing, and it shows as cancelled rather than failed. That gate grades the PR title and body, which this diff does not touch, so it looks unrelated and needs a rerun after the body edit. The other 15 checks pass at this head, including those covering packages/remote. There are no conflicts. After the three fixes above, only that rerun remains before merge.

@zerone0x
zerone0x force-pushed the fix/remote-artifact-nul-name branch from dea29a6 to 192b54f Compare November 23, 2026 14:20
@zerone0x

Copy link
Copy Markdown
Contributor Author

Pushed 192b54f64dbc6ad92b89abe156f232a8a33e43ac on current main for the v0.21.42 compatibility baseline.

  • Ordinary captures check raw fallback names for NUL before taking the basename.
  • Unnamed record stop drops explicit NUL names for video, chunks, and telemetry with artifact_name_invalid. Caller destinations take precedence, and other generated-name cases still pass.
  • The ordinary drive-prefix check uses Windows path rules. Both POSIX colon-name cases wrote to the client working directory.

The same loopback suite went from 6 failures at dea29a6 to 34 passes. All 343 focused tests and 410 related tests passed. Released-wire compatibility passed at protocol 3. The PR body labels the earlier live Chromium run with its tested SHA.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the quick follow-up. All three problems from the earlier review (#4718 (comment)) are fixed at 192b54f, and the code looks good to merge. All 16 checks pass at this commit, including the packages/remote unit lanes that cover daemon-artifacts.ts and the wire-compat gate for the ledger and surface edits. There are no conflicts. Not verified here: the focused tests, the mutation table and the loopback probe were not rerun, and the Windows drop behavior comes from Node path.win32 semantics and a mocked-platform test, not a Windows run. The live Chromium run in the PR body is from dea29a6; this change only touches client path selection, which the loopback tests cover, so a new live run is not needed.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
@thymikee
thymikee merged commit 0d38f89 into callstack:main Nov 23, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A NUL byte in a remote artifact file name crashes the client

2 participants